<?php
namespace app\index\controller;

use app\index\model\AcckuanModel;
use app\index\model\BondFanModel;
use app\index\model\BondJiaoModel;
use app\index\model\BondShouModel;
use app\index\model\ContractCaiJieModel;
use app\index\model\ContractCaiModel;
use app\index\model\FlowBillModel;
use app\index\model\FlowLogModel;
use app\index\model\OptionFeiModel;
use app\index\model\PiaoShouListModel;
use app\index\model\ShouHuanModel;
use app\index\model\ShouXiangKouModel;
use app\index\model\ZhiDaybaoListModel;
use app\index\model\ZhiDaybaoModel;
use app\index\model\ZhiDayfuListModel;
use app\index\model\ZhiDayfuModel;
use app\index\model\ZhiEnbaoListModel;
use app\index\model\ZhiEnbaoModel;
use app\index\model\ZhiJieModel;
use app\index\model\ZhiJintuiListModel;
use app\index\model\ZhiJintuiModel;
use app\index\model\ZhiLianjieModel;
use app\index\model\ZhiTouListModel;
use app\index\model\ZhiTouModel;
use app\index\model\UserModel;
use app\index\model\ZhiXiangListModel;
use app\index\model\ZhiXiangModel;
use app\index\service\EnginService;
use app\index\service\FinanceService;
use app\index\service\FlowService;
use app\index\service\KuanService;
use app\index\service\MenuService;
use app\index\service\OptService;
use app\index\service\PiaoService;
use app\index\service\UserService;
use app\index\service\ZhiService;
use think\Db;
use think\Request;

class Zhi extends Common
{
    public function detail_zhi_tou(Request $request){
        $param = $request->post();
        get_page($param);
        $where[] = ['zhi.deleted_user','=', 0];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name|bill.sericnum|zhi.flowuser','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['sericnum']) && !empty($param['sericnum'])){
            $where[] = ['bill.sericnum','like', '%'.$param['sericnum'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['zhi.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $created_atArr = explode(' - ', $param['created_at']);
            $where[] = ['zhi.created_at','between', [$created_atArr[0].' 00:00:00', $created_atArr[1].' 23:59:59']];
        }
        if(isset($param['feitype']) && !empty($param['feitype'])){
            $where[] = ['list.feitype','=', $param['feitype']];
        }

        $data['feitype'] = (new UserService())->get_option_fei_slet(['xmzc_tbf']);
        $data['is_feitype'] = isset($param['feitype']) ? $param['feitype'] : '';

        $data['data'] = ZhiTouListModel::alias('list')
            ->field('zhi.*,e.name as enginname,bill.sericnum,
            list.feitype,list.money as listmoney,list.explain as listexplain')
            ->join('zhi_tou zhi','zhi.id=list.zhiid')
            ->join('flow_bill bill','bill.id=zhi.billid')
            ->join('engin e','e.id=zhi.enginid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_tou', 'zhi'))
            ->order('e.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = OptionFeiModel::where(['id'=>$item['feilei']])->value('name');
                $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_zhi_tou(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $created_atArr = explode(' - ', $param['created_at']);
            $where[] = ['zhi.created_at','between', [$created_atArr[0].' 00:00:00', $created_atArr[1].' 23:59:59']];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['data'] = ZhiTouModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,bill.sericnum,bill.modename')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_tou', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_tou');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_tou(Request $request){
        $param = $request->post();
        $data = ZhiTouModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiTouModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_tou', $data['id'], '投标费支付');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_tou(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiTouModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);

        $list = ZhiTouListModel::where(['zhiid'=>$data['data']['id']])->select()->toArray();
        foreach ($list as &$item){
            $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
        }
        $data['list'] = $list;

        $data['files'] = (new OptService())->get_file('zhi_tou', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function detail_zhi_xiang(Request $request){
        $param = $request->post();
        get_page($param);
        $where[] = ['zhi.deleted_user','=', 0];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name|bill.sericnum|zhi.flowuser','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['sericnum']) && !empty($param['sericnum'])){
            $where[] = ['bill.sericnum','like', '%'.$param['sericnum'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['zhi.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['feitype_name']) && !empty($param['feitype_name'])){
            $where[] = ['fei.name','like', '%'.$param['feitype_name'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['listexplain']) && !empty($param['listexplain'])){
            $where[] = ['list.explain','like', '%'.$param['listexplain'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['feilei']) && !empty($param['feilei'])){
            $where[] = ['zhi.feilei','=', $param['feilei']];
        }




        if(isset($param['created_at']) && !empty($param['created_at'])){
            $created_atArr = explode(' - ', $param['created_at']);
            $where[] = ['zhi.created_at','between', [$created_atArr[0].' 00:00:00', $created_atArr[1].' 23:59:59']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['feilei'] = (new UserService())->get_option_fei_slet(['xmzc_clf','xmzc_rgf','xmzc_jxsbf','xmzc_zyfbf','xmzc_qtf']);
        $data['is_feilei'] = isset($param['feilei']) ? $param['feilei'] : '';

        $data['feitype'] = (new UserService())->get_option_fei_slet(['xmzc_tbf']);
        $data['is_feitype'] = isset($param['feitype']) ? $param['feitype'] : '';

        $data['data'] = ZhiXiangListModel::alias('list')
            ->field('zhi.*,e.name as enginname,bill.sericnum,fei.name as feitype_name,
            list.feitype,list.money as listmoney,list.explain as listexplain')
            ->join('zhi_xiang zhi','zhi.id=list.zhiid')
            ->join('flow_bill bill','bill.id=zhi.billid')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('option_fei fei','fei.id=list.feitype')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_xiang', 'zhi'))
            ->order('e.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = OptionFeiModel::where(['id'=>$item['feilei']])->value('name');
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_zhi_xiang(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }
        if(isset($param['yijuid']) && !empty($param['yijuid'])){
            $where[] = ['zhi.yijuid','=', $param['yijuid']];
        }
        if(isset($param['feilei_option']) && !empty($param['feilei_option'])){
            $param['feilei'] = (new UserService())->get_optionfeiid_bynum($param['feilei_option']);
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['cainame']) && !empty($param['cainame'])){
            $where[] = ['cai.name','like', '%'.$param['cainame'].'%'];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['feilei']) && !empty($param['feilei'])){
            $where[] = ['zhi.feilei','=', $param['feilei']];
        }
        if(isset($param['yiju']) && !empty($param['yiju'])){
            $where[] = ['zhi.yiju','=', $param['yiju']];
        }
        if(isset($param['piaoqing']) && !empty($param['piaoqing'])){
            $where[] = ['zhi.piaoqing','=', $param['piaoqing']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['feilei'] = (new UserService())->get_option_fei_slet(['xmzc_clf','xmzc_rgf','xmzc_jxsbf','xmzc_zyfbf','xmzc_qtf']);
        $data['is_feilei'] = isset($param['feilei']) ? $param['feilei'] : '';

        $data['yiju'] = (new ZhiService())->get_zhi_xiang_yiju();
        $data['is_yiju'] = isset($param['yiju']) ? $param['yiju'] : '';

        $data['piaoqing'] = (new ZhiService())->get_zhi_xiang_piaoqing();
        $data['is_piaoqing'] = isset($param['piaoqing']) ? $param['piaoqing'] : '';


        $data['data'] = ZhiXiangModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,cai.name as cainame,bill.sericnum,bill.modename')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('contract_cai cai','cai.id=zhi.caiid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_xiang', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = OptionFeiModel::where(['id'=>$item['feilei']])->value('name');
                $item['yiju_name'] = (new ZhiService())->get_zhi_xiang_yiju_name($item['yiju']);
                $item['piaoqing_name'] = (new ZhiService())->get_zhi_xiang_piaoqing_name($item['piaoqing']);
                $item['yijuidinfo'] = (new ZhiService())->get_zhi_xiang_yijuidinfo($item['yiju'], $item['yijuid']);
                $piaoids = PiaoShouListModel::where('id','in',$item['piaoids'])->column('nums');
                $item['piaoids_name'] = implode(',', $piaoids);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_xiang');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_xiang(Request $request){
        $param = $request->post();
        $data = ZhiXiangModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiXiangModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_xiang', $data['id'], '项目付款');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_xiang(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiXiangModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['yiju_name'] = (new ZhiService())->get_zhi_xiang_yiju_name($data['data']['yiju']);
        $data['data']['piaoqing_name'] = (new ZhiService())->get_zhi_xiang_piaoqing_name($data['data']['piaoqing']);

        $data['piaoidsinfo'] = PiaoShouListModel::field('id,shouid,nums')->where('id','in',$data['data']['piaoids'])->select()->toArray();

        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);
        $data['yijuidinfo'] = (new ZhiService())->get_zhi_xiang_yijuidinfo($data['data']['yiju'], $data['data']['yijuid']);

        $list = ZhiXiangListModel::where(['zhiid'=>$data['data']['id']])->select()->toArray();
        foreach ($list as &$item){
            $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
        }
        $data['list'] = $list;

        $data['data']['ben_zhixiang'] = ZhiXiangModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['enginid'=>$data['data']['enginid'],'duier'=>$data['data']['duier']])->sum('money');
        $data['data']['ben_piaoshou'] = PiaoShouListModel::alias('list')
            ->join('piao_shou shou','shou.id=list.shouid')
            ->where(['shou.comid'=>$this->userinfo['comid'],'shou.deleted_user'=>0])
            ->where(['shou.isturn'=>1,'shou.status'=>1])
            ->where(['shou.enginid'=>$data['data']['enginid'],'list.gonger'=>$data['data']['duier']])
            ->sum('list.money');

        $data['data']['ben_caimoney'] = ContractCaiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['enginid'=>$data['data']['enginid'],'gonger'=>$data['data']['duier']])->sum('money');
        $data['data']['ben_caijiemoney'] = ContractCaiJieModel::alias('jie')
            ->join('contract_cai cai','cai.id=jie.caiid')
            ->where(['jie.comid'=>$this->userinfo['comid'],'jie.deleted_user'=>0,'cai.comid'=>$this->userinfo['comid'],'cai.deleted_user'=>0])
            ->where(['jie.isturn'=>1,'jie.status'=>1,'cai.isturn'=>1,'cai.status'=>1])
            ->where(['jie.enginid'=>$data['data']['enginid'],'cai.gonger'=>$data['data']['duier'],'jie.real'=>1])
            ->sum('jie.money');
        $data['data']['ben_shoupiaoweifu'] = round($data['data']['ben_piaoshou'] - $data['data']['ben_zhixiang'], 2);



        $data['data']['quan_zhixiang'] = ZhiXiangModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['duier'=>$data['data']['duier']])->sum('money');
        $data['data']['quan_piaoshou'] = PiaoShouListModel::alias('list')
            ->join('piao_shou shou','shou.id=list.shouid')
            ->where(['shou.comid'=>$this->userinfo['comid'],'shou.deleted_user'=>0])
            ->where(['shou.isturn'=>1,'shou.status'=>1])
            ->where(['list.gonger'=>$data['data']['duier']])
            ->sum('list.money');

        $data['data']['quan_caimoney'] = ContractCaiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['gonger'=>$data['data']['duier']])->sum('money');
        $data['data']['quan_caijiemoney'] = ContractCaiJieModel::alias('jie')
            ->join('contract_cai cai','cai.id=jie.caiid')
            ->where(['jie.comid'=>$this->userinfo['comid'],'jie.deleted_user'=>0,'cai.comid'=>$this->userinfo['comid'],'cai.deleted_user'=>0])
            ->where(['jie.isturn'=>1,'jie.status'=>1,'cai.isturn'=>1,'cai.status'=>1])
            ->where(['cai.gonger'=>$data['data']['duier'],'jie.real'=>1])
            ->sum('jie.money');
        $data['data']['quan_shoupiaoweifu'] = round($data['data']['quan_piaoshou'] - $data['data']['quan_zhixiang'], 2);







        $data['files'] = (new OptService())->get_file('zhi_tou', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }
    public function show_zhi_xiang_you(Request $request){
        $enginid = $request->post('enginid', 0, 'int');
        $duier = $request->post('duier', '', 'string');
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($enginid);
        if($data['engininfo']){
            $data['ben_zhixiang'] = ZhiXiangModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
                ->where(['enginid'=>$data['engininfo']['id'],'duier'=>$duier])->sum('money');
            $data['ben_piaoshou'] = PiaoShouListModel::alias('list')
                ->join('piao_shou shou','shou.id=list.shouid')
                ->where(['shou.comid'=>$this->userinfo['comid'],'shou.deleted_user'=>0])
                ->where(['shou.isturn'=>1,'shou.status'=>1])
                ->where(['shou.enginid'=>$data['engininfo']['id'],'list.gonger'=>$duier])
                ->sum('list.money');

            $data['ben_caimoney'] = ContractCaiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
                ->where(['enginid'=>$data['engininfo']['id'],'gonger'=>$duier])->sum('money');
            $data['ben_caijiemoney'] = ContractCaiJieModel::alias('jie')
                ->join('contract_cai cai','cai.id=jie.caiid')
                ->where(['jie.comid'=>$this->userinfo['comid'],'jie.deleted_user'=>0,'cai.comid'=>$this->userinfo['comid'],'cai.deleted_user'=>0])
                ->where(['jie.isturn'=>1,'jie.status'=>1,'cai.isturn'=>1,'cai.status'=>1])
                ->where(['jie.enginid'=>$data['engininfo']['id'],'cai.gonger'=>$duier,'jie.real'=>1])
                ->sum('jie.money');
            $data['ben_shoupiaoweifu'] = round($data['ben_piaoshou'] - $data['ben_zhixiang'], 2);

        }


        $data['quan_zhixiang'] = ZhiXiangModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['duier'=>$duier])->sum('money');
        $data['quan_piaoshou'] = PiaoShouListModel::alias('list')
            ->join('piao_shou shou','shou.id=list.shouid')
            ->where(['shou.comid'=>$this->userinfo['comid'],'shou.deleted_user'=>0])
            ->where(['shou.isturn'=>1,'shou.status'=>1])
            ->where(['list.gonger'=>$duier])
            ->sum('list.money');

        $data['quan_caimoney'] = ContractCaiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['gonger'=>$duier])->sum('money');
        $data['quan_caijiemoney'] = ContractCaiJieModel::alias('jie')
            ->join('contract_cai cai','cai.id=jie.caiid')
            ->where(['jie.comid'=>$this->userinfo['comid'],'jie.deleted_user'=>0,'cai.comid'=>$this->userinfo['comid'],'cai.deleted_user'=>0])
            ->where(['jie.isturn'=>1,'jie.status'=>1,'cai.isturn'=>1,'cai.status'=>1])
            ->where(['cai.gonger'=>$duier,'jie.real'=>1])
            ->sum('jie.money');
        $data['quan_shoupiaoweifu'] = round($data['quan_piaoshou'] - $data['quan_zhixiang'], 2);

        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_zhi_enbao(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }
        if(isset($param['isdi']) && $param['isdi'] != ''){
            $where[] = ['zhi.isdi','=', $param['isdi']];
        }
        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['data'] = ZhiEnbaoModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,bill.sericnum,bill.modename')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_enbao', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_enbao');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_enbao(Request $request){
        $param = $request->post();
        $data = ZhiEnbaoModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiEnbaoModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_enbao', $data['id'], '项目费用报销');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_enbao(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiEnbaoModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);
        $data['jieidinfo'] = ZhiJieModel::where(['id'=>$data['data']['jieid']])->find();

        $list = ZhiEnbaoListModel::where(['zhiid'=>$data['data']['id']])->select()->toArray();
        foreach ($list as &$item){
            $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
        }
        $data['list'] = $list;

        $data['files'] = (new OptService())->get_file('zhi_enbao', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_zhi_jintui(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name|zhi.zhai|zhi.duier','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';


        $data['data'] = ZhiJintuiModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,bill.sericnum,bill.modename')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_jintui', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = OptionFeiModel::where(['id'=>$item['feilei']])->value('name');
                $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_jintui');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_jintui(Request $request){
        $param = $request->post();
        $data = ZhiJintuiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiJintuiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_jintui', $data['id'], '进项退税');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_jintui(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiJintuiModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['feitype_name'] = OptionFeiModel::where(['id'=>$data['data']['feitype']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);

        $list = ZhiJintuiListModel::where(['zhiid'=>$data['data']['id']])->select()->toArray();
        foreach ($list as &$item){
            $piaoinfo = PiaoShouListModel::where(['id'=>$item['piaoid']])->find();
            $item['nums'] = $piaoinfo['nums'];
            $item['piaotype_name'] = (new PiaoService())->get_kai_piaotype_name($piaoinfo['piaotype']);
            $item['gonger'] = $piaoinfo['gonger'];
            $item['fee'] = $piaoinfo['fee'];
            $item['rate'] = $piaoinfo['rate'];
            $item['ratefee'] = $piaoinfo['ratefee'];
            $item['piaomoney'] = $piaoinfo['money'];
        }
        $data['list'] = $list;

        $data['files'] = (new OptService())->get_file('zhi_jintui', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function detail_kou_zhi_lianjie(Request $request){
        $param = $request->post();
        get_page($param);
        $where[] = ['zhi.deleted_user','=', 0];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name|zhi.flowuser|fei.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['zhi.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['feitype_name']) && !empty($param['feitype_name'])){
            $where[] = ['fei.name','like', '%'.$param['feitype_name'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['listexplain']) && !empty($param['listexplain'])){
            $where[] = ['list.explain','like', '%'.$param['listexplain'].'%'];
        }
        if(isset($param['jiedt']) && !empty($param['jiedt'])){
            $where[] = ['zhi.jiedt','between', explode(' - ', $param['jiedt'])];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $created_atArr = explode(' - ', $param['created_at']);
            $where[] = ['zhi.created_at','between', [$created_atArr[0].' 00:00:00', $created_atArr[1].' 23:59:59']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['data'] = ShouXiangKouModel::alias('list')
            ->field('zhi.*,e.name as enginname,bill.sericnum,
            list.id as listid,list.feitype,list.money as listmoney,list.explain as listexplain,fei.name as feitype_name')
            ->join('zhi_lianjie zhi','zhi.id=list.zhiid')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->leftJoin('option_fei fei','fei.id=list.feitype')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_lianjie', 'zhi'))
            ->order('e.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = '联营费用(扣收)';
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_zhi_lianjie(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['jiedt']) && !empty($param['jiedt'])){
            $where[] = ['zhi.jiedt','between', explode(' - ', $param['jiedt'])];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['data'] = ZhiLianjieModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,bill.sericnum,bill.modename')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_lianjie', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = OptionFeiModel::where(['id'=>$item['feilei']])->value('name');
                $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_lianjie');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_lianjie(Request $request){
        $param = $request->post();
        $data = ZhiLianjieModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiLianjieModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_lianjie', $data['id'], '联营结算');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_lianjie(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiLianjieModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['feitype_name'] = OptionFeiModel::where(['id'=>$data['data']['feitype']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);

        $kou = ShouXiangKouModel::where(['zhiid'=>$data['data']['id']])->select()->toArray();
        foreach ($kou as &$item){
            $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
            $item['lai'] = $item['daikouqiid'] > 0 ? '待扣' : '/';
        }
        $data['kou'] = $kou;

        $data['files'] = (new OptService())->get_file('zhi_lianjie', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_zhi_jie(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }
        if(isset($param['created_user']) && !empty($param['created_user'])){
            $where[] = ['zhi.created_user','=', $param['created_user']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['zhi.duier','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['feitype']) && !empty($param['feitype'])){
            $where[] = ['zhi.feitype','=', $param['feitype']];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $created_atArr = explode(' - ', $param['created_at']);
            $where[] = ['zhi.created_at','between', [$created_atArr[0].' 00:00:00', $created_atArr[1].' 23:59:59']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['feitype'] = (new UserService())->get_option_fei_slet(['wlk_byj']);
        $data['is_feitype'] = isset($param['feitype']) ? $param['feitype'] : '';

        $data['data'] = ZhiJieModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,bill.sericnum,bill.modename')
            ->leftJoin('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_jie', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = OptionFeiModel::where(['id'=>$item['feilei']])->value('name');
                $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_jie');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_jie(Request $request){
        $param = $request->post();
        $data = ZhiJieModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiJieModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_jie', $data['id'], '备用金借支');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_jie(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiJieModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['feitype_name'] = OptionFeiModel::where(['id'=>$data['data']['feitype']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);


        $data['data']['lei_jiefee'] = ZhiJieModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['created_user'=>$data['data']['created_user']])->sum('money');

        $data['data']['lei_huanfee'] = ShouHuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['created_user'=>$data['data']['created_user']])->sum('money');

        $data['data']['lei_difee'] = ZhiEnbaoModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['created_user'=>$data['data']['created_user']])->sum('difee');

        $data['data']['lei_difee'] += ZhiDaybaoModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where(['created_user'=>$data['data']['created_user']])->sum('difee');

        $data['data']['lei_yufee'] = round($data['data']['lei_jiefee'] - $data['data']['lei_huanfee'] - $data['data']['lei_difee'], 2);



        $data['files'] = (new OptService())->get_file('zhi_jie', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_zhi_daybao(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['zhi.zhai','like', '%'.$param['keyword'].'%'];
        }

        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['data'] = ZhiDaybaoModel::alias('zhi')
            ->field('zhi.*,bill.sericnum,bill.modename')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_daybao', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_daybao');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_daybao(Request $request){
        $param = $request->post();
        $data = ZhiDaybaoModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiDaybaoModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_daybao', $data['id'], '日常费用报销');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_daybao(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiDaybaoModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['jieidinfo'] = ZhiJieModel::where(['id'=>$data['data']['jieid']])->find();

        $list = ZhiDaybaoListModel::where(['zhiid'=>$data['data']['id']])->select()->toArray();
        foreach ($list as &$item){
            $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
        }
        $data['list'] = $list;

        $data['files'] = (new OptService())->get_file('zhi_daybao', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function detail_zhi_dayfu(Request $request){
        $param = $request->post();
        get_page($param);
        $where[] = ['zhi.deleted_user','=', 0];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name|bill.sericnum|zhi.flowuser','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['sericnum']) && !empty($param['sericnum'])){
            $where[] = ['bill.sericnum','like', '%'.$param['sericnum'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['listexplain']) && !empty($param['listexplain'])){
            $where[] = ['list.explain','like', '%'.$param['listexplain'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['zhi.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $created_atArr = explode(' - ', $param['created_at']);
            $where[] = ['zhi.created_at','between', [$created_atArr[0].' 00:00:00', $created_atArr[1].' 23:59:59']];
        }
        if(isset($param['feitype']) && !empty($param['feitype'])){
            $where[] = ['list.feitype','=', $param['feitype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['feitype'] = (new UserService())->get_option_fei_slet(['qtzc_qtzc']);
        $data['is_feitype'] = isset($param['feitype']) ? $param['feitype'] : '';

        $data['data'] = ZhiDayfuListModel::alias('list')
            ->field('zhi.*,bill.sericnum,
            list.feitype,list.money as listmoney,list.explain as listexplain')
            ->join('zhi_dayfu zhi','zhi.id=list.zhiid')
            ->join('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_dayfu', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feilei_name'] = OptionFeiModel::where(['id'=>$item['feilei']])->value('name');
                $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_zhi_dayfu(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['zhi.zhai','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['sericnum']) && !empty($param['sericnum'])){
            $where[] = ['bill.sericnum','like', '%'.$param['sericnum'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['zhi.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $created_atArr = explode(' - ', $param['created_at']);
            $where[] = ['zhi.created_at','between', [$created_atArr[0].' 00:00:00', $created_atArr[1].' 23:59:59']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['data'] = ZhiDayfuModel::alias('zhi')
            ->field('zhi.*,bill.sericnum,bill.modename')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('zhi_dayfu', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('zhi_dayfu');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_zhi_dayfu(Request $request){
        $param = $request->post();
        $data = ZhiDayfuModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ZhiDayfuModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'zhi_dayfu', $data['id'], '日常付款');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_zhi_dayfu(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ZhiDayfuModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);

        $list = ZhiDayfuListModel::where(['zhiid'=>$data['data']['id']])->select()->toArray();
        foreach ($list as &$item){
            $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
        }
        $data['list'] = $list;

        $data['files'] = (new OptService())->get_file('zhi_dayfu', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_bond_jiao(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }
        if(isset($param['feitype_option']) && !empty($param['feitype_option'])){
            $param['feitype'] = (new UserService())->get_optionfeiid_bynum($param['feitype_option']);
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['feitype']) && !empty($param['feitype'])){
            $where[] = ['zhi.feitype','=', $param['feitype']];
        }
        if(isset($param['feitype']) && !empty($param['feitype'])){
            $where[] = ['zhi.feitype','=', $param['feitype']];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['feitype'] = (new UserService())->get_option_fei_slet(['wlk_bzj']);
        $data['is_feitype'] = isset($param['feitype']) ? $param['feitype'] : '';


        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['data'] = BondJiaoModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,bill.sericnum,bill.modename')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('bond_jiao', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['shouidinfo'] = BondShouModel::where(['id'=>$item['shouid']])->find();
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('bond_jiao');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_bond_jiao(Request $request){
        $param = $request->post();
        $data = BondJiaoModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            BondJiaoModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'bond_jiao', $data['id'], '保证金缴纳');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_bond_jiao(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = BondJiaoModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['feitype_name'] = OptionFeiModel::where(['id'=>$data['data']['feitype']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);
        $data['shouidinfo'] = BondShouModel::where(['id'=>$data['data']['shouid']])->find();


        $data['files'] = (new OptService())->get_file('bond_jiao', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_bond_fan(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhi.deleted_user','=','0'];
        $where[] = ['zhi.comid','=',$this->userinfo['comid']];
        $where[] = ['zhi.isturn','=',1];
        $where[] = ['zhi.status','in',[0,1]];

        if(isset($param['enginid']) && !empty($param['enginid'])){
            $where[] = ['zhi.enginid','=', $param['enginid']];
        }

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['enginname']) && !empty($param['enginname'])){
            $where[] = ['e.name','like', '%'.$param['enginname'].'%'];
        }
        if(isset($param['duier']) && !empty($param['duier'])){
            $where[] = ['zhi.duier','like', '%'.$param['duier'].'%'];
        }
        if(isset($param['feitype']) && !empty($param['feitype'])){
            $where[] = ['zhi.feitype','=', $param['feitype']];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['zhi.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['incdaotype']) && !empty($param['incdaotype'])){
            $where[] = ['zhi.incdaotype','=', $param['incdaotype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhi.status','=', $param['status']];
        }

        $data['feitype'] = (new UserService())->get_option_fei_slet(['wlk_bzj']);
        $data['is_feitype'] = isset($param['feitype']) ? $param['feitype'] : '';


        $data['incdaotype'] = (new OptService())->get_base_info('cai_income_incdaotype');
        $data['is_incdaotype'] = isset($param['incdaotype']) ? $param['incdaotype'] : '';

        $data['data'] = BondFanModel::alias('zhi')
            ->field('zhi.*,e.name as enginname,bill.sericnum,bill.modename')
            ->join('engin e','e.id=zhi.enginid')
            ->leftJoin('flow_bill bill','bill.id=zhi.billid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('bond_fan', 'zhi'))
            ->order('zhi.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                $item['shouidinfo'] = BondShouModel::where(['id'=>$item['shouid']])->find();
                $item['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
                $item['feitype_name'] = OptionFeiModel::where(['id'=>$item['feitype']])->value('name');
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('bond_fan');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_bond_fan(Request $request){
        $param = $request->post();
        $data = BondFanModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            BondFanModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'bond_fan', $data['id'], '保证金返还');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_bond_fan(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = BondFanModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['feilei_name'] = OptionFeiModel::where(['id'=>$data['data']['feilei']])->value('name');
        $data['data']['feitype_name'] = OptionFeiModel::where(['id'=>$data['data']['feitype']])->value('name');
        $data['data']['incdaotype_name'] = (new OptService())->get_base_showname('cai_income_incdaotype', $data['data']['incdaotype']);
        $data['engininfo'] = (new EnginService())->get_engin_showinfo($data['data']['enginid']);
        $data['shouidinfo'] = BondShouModel::where(['id'=>$data['data']['shouid']])->find();


        $data['files'] = (new OptService())->get_file('bond_fan', $data['data']['id']);
        $data['kuaninfo'] = (new FinanceService())->get_acckuan_info_bybillid($data['data']['billid']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }





}
